

--#include "data\config\activityconfig\fire.lua" once

local npcId = 92
NpcDialog[npcId] = {}
local t = NpcDialog[npcId]

t.main = function(sysarg)
	local dlgStr = string.format(Lang.Activity.v, t.GetFireVal(), Actor.getBuffRemainTimeById(sysarg, ActFireConfig.BuffId))
	dlgStr = string.format("%s\n<#BL%s/@PutWood><#BL%s/@PutWater><#BL%s/@PutAllWood><#BL%s/@PutAllWater><#BLI007%s/@NPCTradeInfoToClient,8>", dlgStr, Lang.Activity.a00214,Lang.Activity.a00215,Lang.Activity.a00221,Lang.Activity.a00222,Lang.Activity.a00216)
	return dlgStr
end

t.PutAllWood = function(sysarg)
	local calcFireVal = 0
	for k, v in ipairs(ActFireConfig.WoodShop) do
		local itemCount = Actor.getItemCount(sysarg, v.id)
		if itemCount > 0 then			
			if Actor.removeItem(sysarg, v.id, itemCount, -1,-1,-1, Lang.LogTips.l00166, 206) then
				calcFireVal = calcFireVal + v.value * itemCount
			end
		end
	end
	if calcFireVal > 0 then
		t.ChangeFireVal(calcFireVal)
		return t.main(sysarg)
	else
		Actor.sendTipmsg(sysarg, Lang.Activity.a00223, ttFlyTip)
	end
end

t.PutAllWater = function(sysarg)
	local calcFireVal = 0
	for k, v in ipairs(ActFireConfig.WaterShop) do
		local itemCount = Actor.getItemCount(sysarg, v.id)
		if itemCount > 0 then			
			if Actor.removeItem(sysarg, v.id, itemCount, -1,-1,-1, Lang.LogTips.l00167, 206) then
				calcFireVal = calcFireVal + v.value * itemCount		
			end
		end
	end
	if calcFireVal < 0 then
		t.ChangeFireVal(calcFireVal)
		System.broadcastTipmsg(string.format(Lang.Activity.a00224, Actor.getName(sysarg)),ttScreenCenter + ttChatWindow)
		return t.main(sysarg)
	else
		Actor.sendTipmsg(sysarg, Lang.Activity.a00220, ttFlyTip)
	end
end

t.GetFireVal = function()
	local sVar = System.getStaticVar()
	return sVar.FireValue or ActFireConfig.MinFireVal
end

--定时减少旺度
t.DeduceFireVal = function()
	local nVal = (ActFireConfig.MaxFireVal - ActFireConfig.MinFireVal)/24
	t.ChangeFireVal(-nVal, true)
end

t.ChangeFireVal = function(nValue, boSys)
	local sVar = System.getStaticVar()
	local fireVal = t.GetFireVal()
	local curFireVal = fireVal + nValue
	if boSys and curFireVal < ActFireConfig.MinFireVal then
		return
	end
	if curFireVal < 0 then
		curFireVal = 0
	end
	sVar.FireValue = curFireVal

	local fVal = ActFireConfig.BaseRate * (curFireVal / (ActFireConfig.MaxFireVal - ActFireConfig.MinFireVal))
	System.setFireValRate(fVal)
end

t.PutWood = function(sysarg)
	local dlgStr = "\n"
	for k, v in ipairs(ActFireConfig.WoodShop) do
		local sItemStr = string.format(Lang.Activity.a00217, Item.getItemName(v.id))
		dlgStr = string.format("%s<#BL%s/@PutThisWood,%d>", dlgStr, sItemStr, k)
	end
	return dlgStr .. Lang.ScriptTips.back001
end

t.PutThisWood = function(sysarg, idx)
	idx = tonumber(idx)
	local itemCfg = ActFireConfig.WoodShop[idx]
	if not itemCfg then
		return
	end
	if Actor.getItemCount(sysarg, itemCfg.id) < itemCfg.count then
		Actor.sendTipmsg(sysarg, string.format(Lang.Activity.a00219, Item.getItemName(itemCfg.id)), ttFlyTip)
		return
	end
	if Actor.removeItem(sysarg, itemCfg.id, itemCfg.count, -1,-1,-1, Lang.LogTips.l00166, 206) then
		t.ChangeFireVal(itemCfg.value)
		return t.main(sysarg)
	end
end

t.PutWater = function(sysarg)
	local dlgStr = "\n"
	for k, v in ipairs(ActFireConfig.WaterShop) do
		local sItemStr = string.format(Lang.Activity.a00217, Item.getItemName(v.id))
		dlgStr = string.format("%s<#BL%s/@PutThisWater,%d>", dlgStr, sItemStr, k)
	end
	return dlgStr .. Lang.ScriptTips.back001
end

t.PutThisWater = function(sysarg, idx)
	idx = tonumber(idx)
	local itemCfg = ActFireConfig.WaterShop[idx]
	if not itemCfg then
		return
	end
	if Actor.getItemCount(sysarg, itemCfg.id) < itemCfg.count then
		Actor.sendTipmsg(sysarg, Lang.Activity.a00220, ttFlyTip)
		return
	end
	if Actor.removeItem(sysarg, itemCfg.id, itemCfg.count, -1,-1,-1, Lang.LogTips.l00167, 206) then
		t.ChangeFireVal(itemCfg.value)
		System.broadcastTipmsg(string.format(Lang.Activity.a00224, Actor.getName(sysarg)),ttScreenCenter + ttChatWindow)
		return t.main(sysarg)
	end
end